package com.user.service.impl;

import com.user.dao.UserMapper;
import com.user.service.UserService;
import org.springframework.stereotype.Service;
import pojo.User;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    UserMapper userMapper;

    /**
     * 查询全部数据
     *
     * @return
     */
    @Override
    public List<User> finAll() {
        return userMapper.selectAll();
    }

    /**
     * 通过id 查询手机号
     *
     * @param id
     * @return
     */
    @Override
    public Integer findPhoneNumberById(Integer id) {
        return userMapper.findPhoneNumberById(id);
    }

    /**
     * 通过用户id查询用户的信息
     *
     * @param userId
     * @return
     */
    @Override
    public User findUserById(Integer userId) {
        return userMapper.selectByPrimaryKey(userId);
    }

    /**
     * 添加操作
     * @param user
     */
    @Override
    public void addUser(User user) {
        userMapper.insert(user);
    }

    /**
     * 通过传来的用户的id，执行删除操作
     * @param userId
     */
    @Override
    public void deleteById(Integer userId) {
        userMapper.deleteByPrimaryKey(userId);
    }

    /**
     * 更新操作
     * @param user
     */
    @Override
    public void update(User user) {
        userMapper.updateByPrimaryKey(user);
    }
}
